package com.srcptit.java.tranning.hoangdd.btvn1;

import java.util.Scanner;

public class Bai8Muc1{
	public static boolean ngto(long n){
		if(n<2)
			return false;
		for(int i=2; i<=Math.sqrt(n); i++)
			if(n%i==0) 
				return false;
		return true;
	}
	
	public static boolean chuso_ngto(long n){
		long a;
		while(n>0){
			a=n%10;
			if(ngto(a) == false)
				return false;
			n/=10;
		}
		return true;
	}
	
	public static boolean day_ko_giam(long n){
		long []a = new long [100];
		int i=1;
		while(n>0){
			a[i]=n%10;
			n/=10;
			i++;
		}
		for(int j=1 ; j<=6; j++)
			if(a[j] < a[j+1])
				return false;
		return true;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(long i=1000000; i<=9999999; i++)
			if(day_ko_giam(i) == true && chuso_ngto(i) == true && ngto(i) == true)
				System.out.println(i);
	}
}

